package org.example.wratablecomparable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 *  WritableComparable排序案例分析（全排序）
 *  包含二次排序
 * @ClassName FlowDriver
 * @Author 小坏
 * @Date 2021/7/16、18:13
 * @Version 1.0
 */
public class FlowDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //1、获取job
        Configuration config = new Configuration();
        Job job = Job.getInstance(config);

        //2、设置jar
        job.setJarByClass(FlowDriver.class);

        //3、关联mapper 和 reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);

        //4、设置mapper 输出的key和value 类型
        job.setMapOutputKeyClass(FlowBean.class);
        job.setMapOutputValueClass(Text.class);

        //5、设置最终数据输出的key和value 类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);
        //6、设置数据的输入和输出路径- >输出数据 是上一个序列化的结果
        FileInputFormat.setInputPaths(job, new Path("D:\\hadoop\\output4"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\hadoop\\output5"));

        //7、提交job
        boolean result = job.waitForCompletion(true);

        System.exit(result ? 0 : 1);

    }
}
